home *** CD-ROM | disk | FTP | other *** search
/ Mac Mania 4 / MacMania 4.toast / / Demo's / Igor Demo Pro / 1 PutContentsIn Igor Pro Folder / WaveMetrics Procedures / Graphing / Drawing Axes < prev    next >
Text File  |  1996-01-29  |  46KB  |  1,638 lines

  1. #pragma rtGlobals= 1
  2.  
  3. Menu "Macros"
  4.     "Draw Derived Axis…", prepDerivedAxis()
  5. end
  6.  
  7. ////////////////////////////////////////////////////////////////////
  8.  
  9. ////////////////////////////////////////////////////////////////////
  10.  
  11. Function prepDerivedAxis()
  12.     Pauseupdate; Silent 1
  13.     
  14.     if (wintype("DerivedAxisControl") == 7)
  15.         DoWindow/F DerivedAxisControl
  16.         return 0
  17.     endif
  18.     
  19.     String dfSav= GetDataFolder(1)
  20.     NewDataFolder/O/S Packages
  21.     NewDataFolder/O/S WM_DrawingAxis
  22.     
  23.     variable/g     gDA_AxisLineWidth=1
  24.     variable/g     gDA_TicsLineWidth=1
  25.     variable/g     gDA_TicLength=0.03
  26.     variable/g     gDA_refAxis=1
  27.     variable/g    gDA_FontSize=10
  28.     variable/g    gDA_FontFace=0
  29.     variable/g     gDA_AxisToDraw=4
  30.     variable/g    gDA_StartDerivedAxis=0
  31.     variable/g     gDA_EndDerivedAxis=100
  32.     variable/g     gDA_LabelGrout=0.02        // QQQ why does this appear to affect which ticks are labeled?
  33.     variable/g    gDA_LineRed
  34.     variable/g    gDA_LineGreen
  35.     variable/g    gDA_LineBlue
  36.     variable/g    gDA_TextRed
  37.     variable/g    gDA_TextGreen
  38.     variable/g    gDA_TextBlue
  39.     variable/g    gDA_SignificantDigits
  40.     variable/g    gDA_LowerLimit=0
  41.     variable/g    gDA_UpperLimit=100
  42.     variable/g    gDA_Interval=20
  43.     variable/g    gDA_requestedTicMarks=5
  44.     String/g    gDA_ScalingFunc    
  45.  
  46. //    Variable/g    gWantsGrids        //  qqq not implemented yet
  47.  
  48.     Execute("DerivedAxisControl()")
  49.     DoWindow /C  DerivedAxisControl
  50.     DoWindow /T  DerivedAxisControl, "Draw Axis Control"
  51.  
  52.     SetDataFolder dfSav
  53. end
  54.  
  55. ////////////////////////////////////////////////////////////////////
  56.  
  57. ////////////////////////////////////////////////////////////////////
  58.  
  59. Function ButtonProcEraseLayer(ctrlName) : ButtonControl
  60.     String ctrlName
  61.  
  62.     String topGraphWindowName=WinName(0,1)        //   find the top graph window
  63.     DoWindow /F  $topGraphWindowName                //   bring to the front
  64.     SetDrawLayer/K    progAxes                        //   erase the whole layer
  65.     DoWindow /F  DerivedAxisControl                    //   bring the panel back to front
  66. End
  67. ////////////////////////////////////////////////////////////////////
  68.  
  69. ////////////////////////////////////////////////////////////////////
  70.  
  71. Function myDrawDerivedAxis()
  72.     NVAR     gDA_AxisLineWidth=root:Packages:WM_DrawingAxis:gDA_AxisLineWidth
  73.     NVAR     gDA_refAxis=root:Packages:WM_DrawingAxis:gDA_refAxis
  74.     NVAR    gDA_StartDerivedAxis=root:Packages:WM_DrawingAxis:gDA_StartDerivedAxis
  75.     NVAR     gDA_EndDerivedAxis=root:Packages:WM_DrawingAxis:gDA_EndDerivedAxis
  76.     NVAR    gDA_LineRed=root:Packages:WM_DrawingAxis:gDA_LineRed
  77.     NVAR    gDA_LineGreen=root:Packages:WM_DrawingAxis:gDA_LineGreen
  78.     NVAR    gDA_LineBlue=root:Packages:WM_DrawingAxis:gDA_LineBlue
  79.     NVAR    gDA_TextRed=root:Packages:WM_DrawingAxis:gDA_TextRed
  80.     NVAR    gDA_TextGreen=root:Packages:WM_DrawingAxis:gDA_TextGreen
  81.     NVAR    gDA_TextBlue=root:Packages:WM_DrawingAxis:gDA_TextBlue
  82.     NVAR     gDA_AxisToDraw=root:Packages:WM_DrawingAxis:gDA_AxisToDraw
  83.     
  84.     
  85.     // get info from the controls now 
  86.     ControlInfo popupNewPosition    
  87.     gDA_AxisToDraw=V_value
  88.     
  89.     ControlInfo popupDerivedScaling    
  90.     variable    scalingType=V_value
  91.     
  92.     variable    defFunc
  93.     Variable    refAxis
  94.     
  95.     gDA_refAxis=refAxis
  96.     
  97.     String topGraphWindowName=WinName(0,1)        //   find the top graph window
  98.     DoWindow /F  $topGraphWindowName
  99.     
  100.     SetDrawEnv xcoord=prel    
  101.     SetDrawEnv ycoord=prel
  102.     // SetDrawLayer/K    progAxes        // qqq     just for testing: cleanup first
  103.     SetDrawLayer    progAxes        
  104.     SetDrawEnv     gstart                    //    start grouping here
  105.     SetDrawEnv xcoord=prel            //    make sure they move correctly with the graph
  106.     SetDrawEnv ycoord=prel
  107.     SetDrawEnv linefgc=(gDA_LineRed,gDA_LineGreen,gDA_LineBlue)
  108.         
  109.     variable     a,b,c,d;
  110.     
  111.     do
  112.         if(gDA_AxisToDraw==1)                //     bottom
  113.             a=1;    b=gDA_StartDerivedAxis/100;    c=gDA_EndDerivedAxis/100;    d=a
  114.             break
  115.         endif
  116.         
  117.         if(gDA_AxisToDraw==4)                //    Top
  118.             a=0;    b=gDA_StartDerivedAxis/100;    c=gDA_EndDerivedAxis/100;    d=a
  119.             break;
  120.         endif
  121.         
  122.         if(gDA_AxisToDraw==3)                //    Right
  123.             d=(100-gDA_StartDerivedAxis)/100;    b=1;    c=1    ;    a=(100-gDA_EndDerivedAxis)/100
  124.         endif
  125.         
  126.         if(gDA_AxisToDraw==2)                //    Left
  127.             d=(100-gDA_StartDerivedAxis)/100;    b=0;    c=0;    a=(100-gDA_EndDerivedAxis)/100
  128.         endif
  129.     while(0)
  130.     
  131.     //  Actually Drawing The Axis     
  132.     if(gDA_AxisLineWidth!=1)
  133.         SetDrawEnv linethick=gDA_AxisLineWidth
  134.     endif
  135.     DrawLine     b,a,c,d        
  136.     
  137.     // Now add the tic marks and labels based on user selected options
  138.     
  139.     // arbitrary scaling based on user specified interval
  140.     if(scalingType==1)            //     User specified interval
  141.         myDrawEqualSpaceTicMarks(gDA_AxisToDraw,a,b,c,d,0)    
  142.     endif    
  143.     
  144.     if(scalingType==2)
  145.         DrawArbTicMarks(gDA_AxisToDraw,a,b,c,d)
  146.     endif
  147.  
  148.     if(gDA_AxisLineWidth!=1)
  149.         SetDrawEnv linethick=1
  150.     endif
  151.     SetDrawEnv gstop            //     end grouping
  152.     SetDrawLayer    UserFront    
  153. end
  154.  
  155. ////////////////////////////////////////////////////////////////////
  156. //
  157. // primitive that draws a centered label for top or bottom axis
  158. // x and y offsets are in plot relative %
  159. //
  160. ////////////////////////////////////////////////////////////////////
  161.  
  162.  
  163. function drawHorizCenterLabel(x1,y1,labelString,offsetx,offsety,fontName,fontSize,fontFace)
  164.     String fontName
  165.     variable fontSize
  166.     variable fontFace
  167.     variable x1,y1,offsetx,offsety
  168.     string    labelString
  169.     String    cmdStr
  170.     
  171.     NVAR    gDA_TextRed=root:Packages:WM_DrawingAxis:gDA_TextRed
  172.     NVAR    gDA_TextGreen=root:Packages:WM_DrawingAxis:gDA_TextGreen
  173.     NVAR    gDA_TextBlue=root:Packages:WM_DrawingAxis:gDA_TextBlue
  174.     NVAR    gDA_FontFace=root:Packages:WM_DrawingAxis:gDA_FontFace
  175.  
  176.     // Note, the following needs to be converted into a string and then executed
  177.     
  178.     execute "SetDrawEnv fname= \""+fontName +"\""
  179.     SetDrawEnv textrgb=(gDA_TextRed,gDA_TextGreen,gDA_TextBlue)
  180.  
  181.     SetDrawEnv     fsize=fontSize
  182.     SetDrawEnv     fstyle=gDA_FontFace
  183.  
  184.     SetDrawEnv textxjust=1
  185.     DrawText x1+offsetx,y1+offsety,labelString
  186. end
  187.  
  188. ////////////////////////////////////////////////////////////////////
  189. //
  190. // primitive that draws a centered label for left or right axis
  191. // x and y offsets are in plot relative fractions
  192. //
  193. ////////////////////////////////////////////////////////////////////
  194.  
  195.  
  196. function drawVertCenterLabel(x1,y1,labelString,offsetx,offsety,fontName,fontSize,fontFace,which)
  197.     String         fontName
  198.     variable     fontSize
  199.     variable     fontFace
  200.     Variable    which
  201.     variable     x1,y1,offsetx,offsety
  202.     string        labelString
  203.     String        cmdStr
  204.     
  205.     NVAR    gDA_TextRed=root:Packages:WM_DrawingAxis:gDA_TextRed
  206.     NVAR    gDA_TextGreen=root:Packages:WM_DrawingAxis:gDA_TextGreen
  207.     NVAR    gDA_TextBlue=root:Packages:WM_DrawingAxis:gDA_TextBlue
  208.     NVAR    gDA_FontFace=root:Packages:WM_DrawingAxis:gDA_FontFace
  209.  
  210.     // Note, the following needs to be converted into a string and then executed
  211.     
  212.     execute("SetDrawEnv     fname=\""+fontName+"\"");
  213.     
  214.     SetDrawEnv     textrgb=(gDA_TextRed,gDA_TextGreen,gDA_TextBlue)
  215.     SetDrawEnv     fsize=fontSize
  216.     SetDrawEnv     fstyle=gDA_FontFace
  217.  
  218.     if(which==3)                            // right axis we want left justified labels
  219.         SetDrawEnv textxjust=0
  220.     else if(which==2)                        // left axis has 
  221.             SetDrawEnv textxjust=2
  222.     endif
  223.     
  224.     SetDrawEnv textyjust=1
  225.     DrawText x1+offsetx,y1+offsety,labelString
  226. end
  227.  
  228.  
  229.  
  230. ////////////////////////////////////////////////////////////////////
  231. //
  232. // primitive that draws a single ticmark
  233. //
  234. ////////////////////////////////////////////////////////////////////
  235.  
  236.  
  237. function drawSingleTic(x1,y1,x2,y2)
  238.     variable x1,y1,x2,y2
  239.  
  240.     NVAR    gDA_LineRed=root:Packages:WM_DrawingAxis:gDA_LineRed
  241.     NVAR    gDA_LineGreen=root:Packages:WM_DrawingAxis:gDA_LineGreen
  242.     NVAR    gDA_LineBlue=root:Packages:WM_DrawingAxis:gDA_LineBlue
  243.     NVAR     gDA_TicsLineWidth=root:Packages:WM_DrawingAxis:gDA_TicsLineWidth
  244.     
  245.     SetDrawEnv linefgc=(gDA_LineRed,gDA_LineGreen,gDA_LineBlue)
  246.     SetDrawEnv linethick=gDA_TicsLineWidth
  247.     DrawLine    x1,y1,x2,y2    
  248. end
  249.  
  250.  
  251. ////////////////////////////////////////////////////////////////////
  252. //
  253. //    make_f_Label:    makes a floating point label based on the number of digits provided
  254. //                    if digits<0     then it uses the default representation (%g)
  255. //
  256. ////////////////////////////////////////////////////////////////////
  257.  
  258. function/S  make_f_Label(value,digits)
  259.     variable/d value,digits
  260.     
  261.     String        formatString="%."
  262.     String        dig=num2str(digits)
  263.     String        labelString
  264.     
  265.     if(digits>=0)
  266.         formatString=formatString+dig+"f"
  267.     else
  268.         formatString="%g"
  269.     endif
  270.         
  271.     if(numType(value)==1)
  272.         labelString="∞"
  273.     else
  274.         sprintf  labelString, formatString ,  value
  275.     endif
  276.     
  277.     return(labelString)
  278. end
  279.  
  280.  
  281. ////////////////////////////////////////////////////////////////////
  282.  
  283. ////////////////////////////////////////////////////////////////////
  284.  
  285. Function drawLineColor()
  286.     DoWindow /F DerivedAxisControl
  287.     SetDrawLayer /K userBack
  288.  
  289.     NVAR    gDA_LineRed=root:Packages:WM_DrawingAxis:gDA_LineRed
  290.     NVAR    gDA_LineGreen=root:Packages:WM_DrawingAxis:gDA_LineGreen
  291.     NVAR    gDA_LineBlue=root:Packages:WM_DrawingAxis:gDA_LineBlue
  292.     NVAR    gDA_TextRed=root:Packages:WM_DrawingAxis:gDA_TextRed
  293.     NVAR    gDA_TextGreen=root:Packages:WM_DrawingAxis:gDA_TextGreen
  294.     NVAR    gDA_TextBlue=root:Packages:WM_DrawingAxis:gDA_TextBlue
  295.  
  296.     SetDrawEnv fillfgc= (gDA_LineRed,gDA_LineGreen,gDA_LineBlue);DelayUpdate
  297.     DrawRect 10,321,60,371
  298.     
  299.     SetDrawEnv fillfgc= (gDA_TextRed,gDA_TextGreen,gDA_TextBlue);DelayUpdate
  300.     DrawRect 240,321,290,371
  301. end
  302.  
  303.  
  304.  
  305. ////////////////////////////////////////////////////////////////////
  306. //
  307. //    draws a set of equally spaced tic marks based 
  308. //    on info entered by the user
  309. //
  310. ////////////////////////////////////////////////////////////////////
  311.  
  312. Function myDrawEqualSpaceTicMarks(which,a,b,c,d,attemptNiceLabels)
  313.     variable        which,attemptNiceLabels
  314.     variable/d          a,b,c,d
  315.  
  316.     NVAR    gDA_SignificantDigits=root:Packages:WM_DrawingAxis:gDA_SignificantDigits
  317.     NVAR    gDA_LowerLimit=root:Packages:WM_DrawingAxis:gDA_LowerLimit
  318.     NVAR    gDA_UpperLimit=root:Packages:WM_DrawingAxis:gDA_UpperLimit
  319.     NVAR    gDA_Interval=root:Packages:WM_DrawingAxis:gDA_Interval
  320.     NVAR     gDA_TicLength=root:Packages:WM_DrawingAxis:gDA_TicLength
  321.     NVAR    gDA_FontSize=root:Packages:WM_DrawingAxis:gDA_FontSize
  322.     NVAR     gDA_LabelGrout=root:Packages:WM_DrawingAxis:gDA_LabelGrout
  323.     NVAR    gDA_FontFace=root:Packages:WM_DrawingAxis:gDA_FontFace
  324.  
  325.     variable         numDigits=gDA_SignificantDigits;
  326.     
  327.     
  328.     GetWindow $WinName(0,1), psize
  329.     variable plotWidth=V_right-V_left
  330.     variable plotHeight=V_bottom-V_top
  331.         
  332.     if(gDA_Interval==0)
  333.         Abort "Interval value should not be zero"
  334.         // since abort does not work as one would expect,
  335.         // the following will set default to 5 ticks
  336.         gDA_Interval=(gDA_UpperLimit-gDA_LowerLimit)/5
  337.     endif
  338.     
  339.     variable     nTics=(gDA_UpperLimit-gDA_LowerLimit)/gDA_Interval
  340.     
  341.     if(nTics==0)
  342.         Abort    "The number of tick-marks must be positive."
  343.         return(0);
  344.     else
  345.         if(nTics>99)
  346.             Abort    "The number of tick-marks should not exceed 99."
  347.             return(0);
  348.         endif
  349.     endif
  350.     
  351.     // now lets see if it generates "nice" labels
  352.     
  353.  
  354.     if(attemptNiceLabels)
  355.         if((numType(gDA_LowerLimit)!=0) %| (numType(gDA_UpperLimit)!=0))
  356.             beep
  357.             print "Round labels are not enabled for infinite limits."
  358.         else
  359.             Make /o/N=5 tmpData        
  360.             tmpData[0]=gDA_LowerLimit
  361.             tmpData[1]=gDA_UpperLimit
  362.             tmpData[2]=nTics
  363.                 
  364.             makeSmartLabels(tmpData)
  365.             
  366.             gDA_LowerLimit=tmpData[0]
  367.             gDA_UpperLimit=tmpData[1]
  368.             nTics=tmpData[2]
  369.             numDigits=tmpData[4]
  370.             killWaves tmpData
  371.         endif
  372.     endif
  373.     
  374.     if(nTics<1)
  375.         Abort    "The number of tick-marks must be greater than 1."
  376.         return(0);
  377.     else
  378.         if(nTics>99)
  379.             Abort    "The number of tick-marks should not exceed 99."
  380.             return(0);
  381.         endif
  382.     endif
  383.     
  384.     gDA_Interval=(gDA_UpperLimit-gDA_LowerLimit)/nTics
  385.         
  386.     // case statement should start here
  387.     // but we are just testing now
  388.     
  389.     variable    maxPosition,minPosition
  390.     variable    y1,y2,x1,x2
  391.     variable     delta
  392.     variable/d    valueAtTic
  393.     string        labelString
  394.     String        formatString="%."
  395.     String        dig=num2str(numDigits)
  396.     
  397.     formatString=formatString+dig+"f"
  398.     
  399.     variable    value=gDA_LowerLimit
  400.     
  401.     ControlInfo/W=DerivedAxisControl popupFont
  402.     String fontStringName=S_value
  403.     
  404.     variable fontFace=gDA_FontFace            
  405.             
  406.     // case statement for the different locations of the derived axis
  407.     //
  408.     do
  409.         if(which==4)                        // Top Axis
  410.             maxPosition=c
  411.             minPosition=b
  412.             delta=((maxPosition-minPosition)/nTics)
  413.             y1=0
  414.             y2=- gDA_TicLength
  415.             do
  416.                 x1=c-nTics*delta
  417.                 drawSingleTic(x1,y1,x1,y2)
  418.                 sprintf  labelString, formatString , value
  419.                 drawHorizCenterLabel(x1,y1,labelString,0,-gDA_LabelGrout-gDA_TicLength,fontStringName,gDA_FontSize,fontFace)
  420.                 nTics -=1
  421.                 value+=gDA_Interval
  422.             while(nTics>=0)
  423.             break;
  424.         endif
  425.         
  426.         if(which==1)                        // Bottom Axis
  427.             maxPosition=c
  428.             minPosition=b
  429.             delta=((maxPosition-minPosition)/nTics)
  430.             y1=1
  431.             
  432.             // the label needs to be dropped down by the ascent of the font as a ratio to the size of the plot 
  433.             // since we are in plot relative coordinates
  434.             
  435.             y2=1+gDA_TicLength
  436.             variable extraV=gDA_LabelGrout+FontSizeHeight(fontStringName, gDA_FontSize,fontFace)/plotHeight
  437.             
  438.             // Now draw the tic marks and labels
  439.             do
  440.                 x1=maxPosition-nTics*delta
  441.                 drawSingleTic(x1,y1,x1,y2)
  442.                 sprintf  labelString, formatString , value
  443.                 drawHorizCenterLabel(x1,y2,labelString,0,extraV,fontStringName,gDA_FontSize,fontFace)
  444.                 nTics -=1
  445.                 value+=gDA_Interval
  446.             while(nTics>=0)
  447.             break;
  448.         endif
  449.         
  450.         if(which==2)                        // Left Axis
  451.             maxPosition=a
  452.             minPosition=d
  453.             delta=((maxPosition-minPosition)/nTics)
  454.             x1=0
  455.             x2=-gDA_TicLength
  456.             variable len
  457.             do
  458.                 y1=maxPosition-nTics*delta        
  459.                 y2=y1
  460.                 drawSingleTic(x1,y1,x2,y2)
  461.                 sprintf  labelString, formatString , value
  462.                 drawVertCenterLabel(x1,y1,labelString,-gDA_LabelGrout-gDA_TicLength,0,fontStringName,gDA_FontSize,fontFace,which)
  463.                 nTics -=1
  464.                 value+=gDA_Interval
  465.             while(nTics>=0)
  466.             break;
  467.         endif
  468.         
  469.         if(which==3)                        // Right Axis
  470.             maxPosition=a
  471.             minPosition=d
  472.             delta=((maxPosition-minPosition)/nTics)
  473.             x1=1
  474.             x2=1+gDA_TicLength
  475.             do
  476.                 y1=maxPosition-nTics*delta        
  477.                 drawSingleTic(x1,y1,x2,y1)
  478.                 sprintf  labelString, formatString ,  value
  479.                 drawVertCenterLabel(x1,y1,labelString,gDA_LabelGrout+gDA_TicLength,0,fontStringName,gDA_FontSize,fontFace,which)
  480.                 nTics -=1
  481.                 value+=gDA_Interval
  482.             while(nTics>=0)
  483.             break;
  484.         endif
  485.         
  486.     while(0)    
  487.     
  488. end
  489.  
  490. ////////////////////////////////////////////////////////////////////
  491. //
  492. //    Draw tic marks and labels based on the scaling function and
  493. //    the axis which is used as scaling origin.  The numerical labels
  494. //    depends on a popup menu choice between "hard wired" i.e., the
  495. //    labels just go at equal intervals without control over the value
  496. //    the label displays.  The second choice is "nice labels" which
  497. //    will be placed at nice values which may or may not span the
  498. //    interval well in the case of highly non-linear functions.  The
  499. //    third choice is to have the tick-marks and the labels placed 
  500. //    based on a user-specified wave.
  501. //
  502. ////////////////////////////////////////////////////////////////////
  503.  
  504. Function DrawArbTicMarks(which,a,b,c,d)    
  505.     variable    which
  506.     variable/d      a,b,c,d
  507.     
  508.     variable    numTics=5
  509.     variable    numDigits=4
  510.     
  511.     variable     xmin,xmax
  512.     String        getAxisString
  513.     
  514.     // first find which axis we are scaling
  515.     // the following will support any axis, allowing the strange ability
  516.     // to scale an axis based on a perpendicular axis.
  517.     
  518.     ControlInfo/W=DerivedAxisControl  popupLabelingType
  519.     variable    options=V_value
  520.  
  521.     ControlInfo/W=DerivedAxisControl popupRefAxis
  522.     String refAxisName=S_value
  523.     
  524.     if(strlen(refAxisName)<=0)
  525.         Abort "You must specify a reference axis."
  526.         return(0)
  527.     endif
  528.     
  529.     GetAxis/Q  $refAxisName
  530.     
  531.     if((V_Max-V_Min)==0)
  532.         beep
  533.         print V_Max,V_Min
  534.         Abort "Check your selection of scaled axis"
  535.     endif
  536.         
  537.     if(numTics==0)
  538.         Abort "The number of tic marks must be positive"
  539.     endif
  540.     
  541.     do
  542.         if(options==1)
  543.             doHardWired(which,a,b,c,d,V_Min,V_Max)
  544.             break
  545.         endif
  546.         
  547.         if(options==2)
  548.             doNiceLabels(which,a,b,c,d,V_Min,V_Max)
  549.             break
  550.         endif
  551.         
  552.         if(options==3)
  553.             String    theName="tmp_qq_Params"
  554.             Make /o/N=9     tmp_qq_Params
  555.                 tmp_qq_Params[0]=which
  556.                 tmp_qq_Params[1]=a
  557.                 tmp_qq_Params[2]=b 
  558.                 tmp_qq_Params[3]=c
  559.                 tmp_qq_Params[4]=d
  560.                 tmp_qq_Params[5]=numTics
  561.                 tmp_qq_Params[6]=V_Min
  562.                 tmp_qq_Params[7]=V_Max
  563.             useTicMarkWave(theName)
  564.             killWaves tmp_qq_Params
  565.             break
  566.         endif
  567.     while(0)
  568. end
  569.  
  570.  
  571. ////////////////////////////////////////////////////////////////////
  572. //
  573. //    useTicMarkWave:    Asks the user which wave to use and then performs some
  574. //                        tests on the data.  If all is ok, the datapoints in the wave
  575. //                        are used to label the axis.  
  576. //                        We assume that the specified wave is in terms of target 
  577. //                        domain so in order to find where the tic marks go, we need
  578. //                        to calculate the inverse function for the true x-location and
  579. //                        then to scale it to plot relative coordinates.  To expedite the
  580. //                        search for the true x-location we store the last point found
  581. //                        to serve as a starting point for the next search.
  582. //
  583. ////////////////////////////////////////////////////////////////////
  584.  
  585. Function useTicMarkWave(params)
  586.     String    params
  587.     variable numDigits
  588.  
  589.     NVAR gDA_SignificantDigits=root:Packages:WM_DrawingAxis:gDA_SignificantDigits
  590.  
  591.     ControlInfo/W=DerivedAxisControl popupTicWave
  592.     String wave_Name= S_Value
  593.     if(strlen(wave_Name)<=0)
  594.         abort "You must specify a tick-mark wave."
  595.         return 0
  596.     endif
  597.     drawTickMarkWave(params,gDA_SignificantDigits,wave_Name)
  598. end
  599.  
  600.  
  601. ////////////////////////////////////////////////////////////////////
  602.  
  603.  
  604. ////////////////////////////////////////////////////////////////////
  605.  
  606. Function SetWaveBasedOnString(w,  x0, x1, n)
  607.     String w
  608.     Variable/D     x0, x1
  609.     Variable n
  610.         
  611.     SVAR    gDA_ScalingFunc=root:Packages:WM_DrawingAxis:gDA_ScalingFunc
  612.     
  613.     if(strlen(gDA_ScalingFunc)<=0)
  614.         abort "You must specify a function for this mode."
  615.         return(-1)
  616.     endif
  617.     
  618.     if(n<=1)
  619.         beep
  620.         print  "At least two tick-marks are required."
  621.         return(-1)
  622.     endif
  623.     
  624.     String cmd
  625.     Make/O/D/N=(n) $w
  626.     SetScale/I x x0, x1, $w
  627.     sprintf cmd, "%s = %s", w,gDA_ScalingFunc
  628. //print cmd
  629.     Execute cmd
  630.     
  631.     return(0)
  632. End
  633.  
  634. ////////////////////////////////////////////////////////////////////
  635. //
  636. //    doNiceLabels:       Attempts to look at the new interval and generate a set of nice 
  637. //                    rounded labels that will fall inside the boundaries set by the 
  638. //                    existing axis.
  639. //
  640. ////////////////////////////////////////////////////////////////////
  641.  
  642. Function doNiceLabels(which,a,b,c,d,vmin,vmax)
  643.     Variable     which,a,b,c,d,vmin,vmax
  644.     String        scalingFunc
  645.     
  646.     NVAR     gDA_requestedTicMarks=root:Packages:WM_DrawingAxis:gDA_requestedTicMarks
  647.     NVAR    gDA_SignificantDigits=root:Packages:WM_DrawingAxis:gDA_SignificantDigits
  648.  
  649.     // find the nice labels and load them on a wave which is passed to 
  650.     
  651.  
  652.     variable    numTics=gDA_requestedTicMarks
  653.     variable    numDigits=gDA_SignificantDigits
  654.     variable    localTics=numTics+2,newXmin,newXmax
  655.     variable    oldXmin,oldXmax
  656.     variable    switchDir=1
  657.     variable    interval
  658.     variable     numMinorTics
  659.     
  660.     
  661.     //
  662.     // calculate the limits and make sure that min<max after scaling
  663.     //
  664.     
  665.     String tmpName="tmpDDD"
  666.     if(SetWaveBasedOnString(tmpName,vmin, vmax,2))
  667.         return(-1)
  668.     endif
  669.         
  670.     Wave ww=$tmpName
  671.     newXmin=ww[0]
  672.     newXmax=ww[1]
  673.     
  674.     if((numType(newXmin)!=0) %| (numType(newXmax)!=0))
  675.         beep
  676.         print "Rounded labels can only apply to a finite range."
  677.         return(-1)
  678.     endif
  679.     
  680.     oldXmin=newXmin
  681.     oldXmax=newXmax
  682.     KillWaves ww
  683.         
  684.     //
  685.     // set them in the right order and keep a flag around
  686.     //
  687.     
  688.     if(newXmin>newXmax)
  689.         switchDir=newXmin
  690.         newXmin=newXmax
  691.         newXmax=switchDir
  692.         switchDir=-1
  693.     endif
  694.     
  695.     
  696.     Make /o/N=5 tmp_LabelsWave
  697.     tmp_LabelsWave[0]=newXmin
  698.     tmp_LabelsWave[1]=newXmax
  699.     tmp_LabelsWave[2]=numTics+2
  700.     
  701.     // numMinorTics=w[3],numDigits=w[4]            // not implemented yet
  702.  
  703.     //
  704.     // run a loop until it is happy with the number of tick marks;
  705.     // require that there are at least 3(+2) tic-marks when we are done
  706.     //
  707.     
  708.     do
  709.         makeSmartLabels(tmp_LabelsWave)
  710.         if(tmp_LabelsWave[2]>5)
  711.             newXmin=tmp_LabelsWave[0]
  712.             newXmax=tmp_LabelsWave[1]
  713.             numTics=tmp_LabelsWave[2]
  714.             numMinorTics=tmp_LabelsWave[3]
  715.             numDigits=tmp_LabelsWave[4]
  716.             if(numDigits>=1)
  717.                 numDigits-=1
  718.             endif
  719.             interval=(newXmax-newXmin)/numTics
  720.             
  721.             KillWaves tmp_LabelsWave
  722.             break;
  723.         endif
  724.         
  725.         localTics+=1
  726.         tmp_LabelsWave[0]=newXmin
  727.         tmp_LabelsWave[1]=newXmax
  728.         tmp_LabelsWave[2]=localTics
  729.     while(1)
  730.     
  731.     localTics=numTics
  732.     
  733.     //
  734.     // while the direction of the limits are still from small to large
  735.     //
  736.     
  737.     if(newXmin>=oldXmin)
  738.         localTics+=1
  739.         newXmin-=interval
  740.     endif
  741.     
  742.     if(newXmax<=oldXmax)
  743.         localTics+=1
  744.     endif
  745.     
  746.     //
  747.     // reset the directions if it was changed before
  748.     //
  749.     
  750.     if(switchDir==-1)
  751.         switchDir=newXmin
  752.         newXmin=newXmax
  753.         newXmax=switchDir
  754.         switchDir=-1
  755.     endif
  756.     
  757.     // now drop the outer two tick marks
  758.     localTics-=1
  759.     
  760.     variable i=0
  761.     String waveNameStr="tmp_qq_tics"
  762.     Make /N=(localTics+1) tmp_qq_tics
  763.     
  764.     do
  765.         tmp_qq_tics[i]=newXmin+switchDir*i*interval
  766.         i+=1
  767.     while(i<=localTics)
  768.     
  769.     
  770.     String paramsStr="tmp_qq_params"
  771.     Make /o/N=8 tmp_qq_params
  772.     tmp_qq_params[0]=which
  773.     tmp_qq_params[1]=a
  774.     tmp_qq_params[2]=b
  775.     tmp_qq_params[3]=c
  776.     tmp_qq_params[4]=d
  777.     tmp_qq_params[5]=localTics+1
  778.     tmp_qq_params[6]=vmin
  779.     tmp_qq_params[7]=vmax
  780.     
  781.     drawTickMarkWave(paramsStr,numDigits,waveNameStr)
  782.     KillWaves tmp_qq_params,tmp_qq_tics
  783. end
  784.  
  785. ////////////////////////////////////////////////////////////////////
  786. //
  787. //        drawTickMarkWave:    is called from doNiceLabels() and from 
  788. //                                useTicmarkWave().  It takes the provided wave
  789. //                                and finds the x-location at which to place the tics
  790. //                                using Igor call FindLevel.
  791. //
  792. ////////////////////////////////////////////////////////////////////
  793.  
  794. Function drawTickMarkWave(params,numDigits,waveNameStr)
  795.     String         params,waveNameStr
  796.     variable     numDigits
  797.  
  798.     NVAR    gDA_FontSize=root:Packages:WM_DrawingAxis:gDA_FontSize
  799.     NVAR     gDA_TicLength=root:Packages:WM_DrawingAxis:gDA_TicLength
  800.     NVAR     gDA_LabelGrout=root:Packages:WM_DrawingAxis:gDA_LabelGrout
  801.     NVAR    gDA_FontFace=root:Packages:WM_DrawingAxis:gDA_FontFace
  802.         
  803.     variable         whichAxis,a,b,c,d,numTics,axmin,axmax
  804.     Wave            theParams=$params
  805.     
  806.     Duplicate/o     $waveNameStr,pointsWave
  807.     
  808.     whichAxis=        theParams[0]
  809.     a=                theParams[1]
  810.     b=                theParams[2]
  811.     c=                theParams[3]
  812.     d=                theParams[4]
  813.     numTics=        theParams[5]
  814.     axmin=            theParams[6]
  815.     axmax=            theParams[7]
  816.         
  817.     GetWindow kwTopWin,psize
  818.     variable plotWidth=V_right-V_left
  819.     variable plotHeight=V_bottom-V_top
  820.     variable maxPosition,minPosition
  821.     maxPosition=c
  822.     minPosition=b
  823.     variable delta,y1,y2,x1,x2
  824.     delta=axmax-axmin
  825.     variable scaleFactor                            // used for partial axis drawing
  826.     
  827.     //  Now we test that the requested tic marks are within range
  828.     //  of the new scaled axis
  829.     
  830.     variable numberOfPoints=numpnts(pointsWave)
  831.  
  832.     variable ymin,ymax
  833.     String  tmpWaveStr="tmpddd"
  834.     
  835.     if(SetWaveBasedOnString(tmpWaveStr,axmin,axmax,2))
  836.         return(-1)
  837.     endif
  838.     
  839.     Wave ddd=$tmpWaveStr
  840.     ymin=ddd[0]
  841.     ymax=ddd[1]
  842.     KillWaves ddd
  843.         
  844.     variable flipLimitsFlag=0            
  845.             
  846.     if(ymax<ymin)                        //  make sure we have it in the correct order
  847.         flipLimitsFlag=ymin
  848.         ymin=ymax
  849.         ymax=flipLimitsFlag
  850.         flipLimitsFlag=1
  851.     endif
  852.     
  853.     ControlInfo/W=DerivedAxisControl popupFont
  854.     String fontStringName=S_value
  855.  
  856.     //  test to see that all points in the wave are within limits
  857.     
  858.     variable i=0    
  859.     do
  860.         if((pointsWave[i]>ymax) %| (pointsWave[i]<ymin))
  861.             String  mess
  862.             mess="Data point "+num2str(pointsWave[i]) + " is out of range."
  863.             pointsWave[i]=NaN
  864.         endif
  865.         i+=1
  866.     while(i<numberOfPoints)
  867.     
  868.                                         //  if we flipped the limits before, restore them
  869.     if(flipLimitsFlag==1)
  870.         flipLimitsFlag=ymin
  871.         ymin=ymax
  872.         ymax=flipLimitsFlag
  873.         flipLimitsFlag=1
  874.     endif
  875.     
  876.                                         //  Now go through all tic marks specified in the wave
  877.  
  878.     String    labelString
  879.     variable horizontalPosition=-1
  880.     variable newPosition
  881.     variable lastx=axmin
  882.     
  883.     // load a wave of 1000 points with the data 
  884.     
  885.     String tmpString="tmpXPoints"
  886.     if(SetWaveBasedOnString("tmpXPoints",axmin,axmax,1000))
  887.         return(-1)
  888.     endif
  889.     
  890.     Wave tmpXPoints=$tmpString
  891.     
  892.     i=0
  893.     do
  894.         if((whichAxis==4) %| (whichAxis==1))
  895.             variable yOffset
  896.             scaleFactor=(c-b)/delta
  897.             if(whichAxis==4)
  898.                 y1=0
  899.                 y2=-gDA_TicLength
  900.                 yOffset=-gDA_LabelGrout-gDA_TicLength
  901.             else
  902.                 y1=1
  903.                 y2=1+gDA_TicLength
  904.                 yOffset=gDA_LabelGrout+gDA_TicLength+gDA_FontSize/plotHeight                    // 10=fontsize
  905.             endif
  906.  
  907.             do
  908.                 if(numtype(pointsWave[i])==0)                            // skip NaN's and the like
  909.                     //  gave only one tick FindLevel /Q/R=(lastx,axmax) tmpXPoints, pointsWave[i]
  910.                     FindLevel /Q/R=(axmin,axmax) tmpXPoints, pointsWave[i]
  911.                     if(V_flag==0)                                            // only if a solution was found
  912.                         x1=V_levelX
  913.                         lastx=x1                                            // know where to start the search
  914.                         x1=b+scaleFactor*(x1-axmin)                    // prel value
  915.                         
  916.                         drawSingleTic(x1,y1,x1,y2)
  917.                         labelString=make_f_Label(pointsWave[i],numDigits)
  918.                         newPosition=x1-(FontSizeStringWidth(fontStringName,gDA_FontSize , 0, labelString)/plotWidth)/2
  919.                         if((horizontalPosition<newPosition) %| (horizontalPosition<0 )) %| (flipLimitsFlag==0))
  920.                             drawHorizCenterLabel(x1,y1,labelString,0,yOffset,fontStringName,gDA_FontSize,gDA_FontFace)
  921.                             horizontalPosition=x1+(FontSizeStringWidth(fontStringName,gDA_FontSize , gDA_FontFace, labelString)/plotWidth)/2
  922.                         endif
  923.                     endif
  924.                 endif
  925.                 i +=1
  926.             while(i<numberOfPoints)
  927.             break;
  928.         endif
  929.         
  930.         //
  931.         //    Handle the case of the two vertical axes
  932.         //
  933.         
  934.         if((whichAxis==2) %| (whichAxis==3))
  935.             maxPosition=a
  936.             minPosition=d
  937.             Variable xOffset
  938.             scaleFactor=(d-a)/delta
  939.             
  940.             if(whichAxis==3)
  941.                 x1=1
  942.                 x2=1+gDA_TicLength
  943.                 xOffset=0.03+gDA_TicLength
  944.             else
  945.                 x1=0
  946.                 x2=-gDA_TicLength
  947.                 xOffset=-gDA_TicLength
  948.             endif
  949.             
  950.             do
  951.                 if(numtype(pointsWave[i])==0)                            // skip NaN's and the like
  952.                     FindLevel /Q/R=(lastx,axmax) tmpXPoints, pointsWave[i]
  953.                     if(V_flag==0)                                            // only if a solution was found
  954.                         y1=V_levelX
  955.                         lastx=y1                                            // know where to start the search
  956.                         y1=minPosition-(y1-axmin)*scaleFactor                // prel value
  957.                         drawSingleTic(x1,y1,x2,y1)
  958.                         labelString=make_f_Label(pointsWave[i],numDigits)
  959.                         drawVertCenterLabel(x1,y1,labelString,xOffset,0,fontStringName,gDA_FontSize,gDA_FontFace,whichAxis)
  960.                     endif
  961.                 endif
  962.                 i +=1
  963.             while(i<numberOfPoints)
  964.             break;
  965.         endif
  966.     while(0)
  967.     
  968.     KillWaves tmpXPoints,pointsWave
  969. end
  970.  
  971.  
  972. ////////////////////////////////////////////////////////////////////
  973. //
  974. //    doHardWired:  draws hard wired tic marks with labels
  975. //    according to the distances provided by the min and max
  976. //    and by the number of intervals.  If the labels are too long
  977. //    the label may be skipped although the tic mark is drawn.
  978. //
  979. //    Note that there are no tests to find if the labels fall inside
  980. //    the margins of the graph and there are no changes to the current
  981. //    setting of the margins.
  982. //
  983. ////////////////////////////////////////////////////////////////////
  984.  
  985. function doHardWired(which,a,b,c,d,xmin,xmax)
  986.     variable which,a,b,c,d,xmin,xmax
  987.     String         scalingF
  988.     
  989.     NVAR     gDA_requestedTicMarks=root:Packages:WM_DrawingAxis:gDA_requestedTicMarks
  990.     NVAR    gDA_FontSize=root:Packages:WM_DrawingAxis:gDA_FontSize
  991.     NVAR     gDA_TicLength=root:Packages:WM_DrawingAxis:gDA_TicLength
  992.     NVAR     gDA_LabelGrout=root:Packages:WM_DrawingAxis:gDA_LabelGrout
  993.     NVAR    gDA_SignificantDigits=root:Packages:WM_DrawingAxis:gDA_SignificantDigits
  994.     NVAR    gDA_FontFace=root:Packages:WM_DrawingAxis:gDA_FontFace
  995.  
  996.     
  997.     variable    numTics=gDA_requestedTicMarks
  998.  
  999.     ControlInfo/W=DerivedAxisControl funcString    
  1000.     if(strlen(S_value)<=0)
  1001.         abort "You must specify a function for this mode."
  1002.         return(-1)
  1003.     endif
  1004.     
  1005.     
  1006.     GetWindow kwTopWin,psize
  1007.     variable plotWidth=V_right-V_left
  1008.     variable plotHeight=V_bottom-V_top
  1009.     variable maxPosition,minPosition
  1010.     variable delta
  1011.     variable interval=(xmax-xmin)/numTics
  1012.     variable value=xmin
  1013.     variable x1,x2,y1,y2
  1014.     String    labelString
  1015.     variable horizontalPosition=-1
  1016.     variable newPosition
  1017.  
  1018.     String tmpFileName="tmp_yy"
  1019.     if(SetWaveBasedOnString(tmpFileName,xmin,xmax,numTics+1))
  1020.         return(-1)
  1021.     endif
  1022.     
  1023.     wave w=$tmpFileName
  1024.         
  1025.     variable i=0
  1026.     variable yOffset
  1027.     ControlInfo/W=DerivedAxisControl setvarFontSize
  1028.     gDA_FontSize=V_value
  1029.  
  1030.     ControlInfo/W=DerivedAxisControl popupFont
  1031.     String fontStringName=S_value
  1032.     
  1033.     do
  1034.         if((which==4) %| (which==1))
  1035.             maxPosition=c
  1036.             minPosition=b
  1037.             delta=((maxPosition-minPosition)/numTics)
  1038.             if(which==4)
  1039.                 y1=0
  1040.                 y2=-gDA_TicLength
  1041.                 yOffset=-gDA_LabelGrout-gDA_TicLength
  1042.             endif
  1043.             
  1044.             if(which==1)
  1045.                 y1=1
  1046.                 y2=1+gDA_TicLength
  1047.                 yOffset=gDA_LabelGrout+gDA_TicLength+gDA_FontSize/plotHeight  
  1048.             endif
  1049.  
  1050.             do
  1051.                 x1=c-numTics*delta
  1052.                 drawSingleTic(x1,y1,x1,y2)
  1053.                 labelString=make_f_Label(w[i],gDA_SignificantDigits)
  1054.                 newPosition=x1-(FontSizeStringWidth(fontStringName,gDA_FontSize , gDA_FontFace, labelString)/plotWidth)/2
  1055.                 if((horizontalPosition<newPosition) %| (horizontalPosition<0 ))
  1056.                     drawHorizCenterLabel(x1,y1,labelString,0,yOffset,fontStringName,gDA_FontSize,gDA_FontFace)
  1057.                     horizontalPosition=x1+gDA_LabelGrout+(FontSizeStringWidth(fontStringName,gDA_FontSize , gDA_FontFace, labelString)/plotWidth)/2
  1058.                 endif
  1059.                 numTics -=1
  1060.                 i +=1
  1061.             while(numTics>=0)
  1062.             break;
  1063.         endif
  1064.         
  1065.         //
  1066.         //    Left and right axes are handled here.   
  1067.         //
  1068.         
  1069.         
  1070.         if((which==2) %| (which==3))
  1071.             maxPosition=a
  1072.             minPosition=d
  1073.             delta=((maxPosition-minPosition)/numTics)
  1074.             variable xOffset=gDA_LabelGrout+gDA_TicLength
  1075.             if(which==3)
  1076.                 x1=1
  1077.                 x2=1+gDA_TicLength
  1078.             else
  1079.                 x1=0
  1080.                 x2=-gDA_TicLength
  1081.                 xOffset=-xOffset
  1082.             endif
  1083.             do
  1084.                 y1=maxPosition-numTics*delta        
  1085.                 drawSingleTic(x1,y1,x2,y1)
  1086.                 labelString=make_f_Label(w[i],gDA_SignificantDigits)
  1087.                 drawVertCenterLabel(x1,y1,labelString,xOffset,0,fontStringName,gDA_FontSize,gDA_FontFace,which)
  1088.                 numTics -=1
  1089.                 i +=1
  1090.             while(numTics>=0)
  1091.             break
  1092.         endif
  1093.         
  1094.         if(which!=0)
  1095.             Abort "Feature Not Implemented;  Look for next ver. "
  1096.         endif
  1097.     while(0)
  1098.     
  1099.     KillWaves w
  1100. end
  1101.  
  1102. //    The following function takes a wave as an input.  The wave consists of 5 parameters
  1103. //    which the function will modify.  On input the first two parameters are the min and max
  1104. //    range.  On output the first two parameters are the min and max values that will give
  1105. //    "nice" values when used with the determined number of tic marks.
  1106. //    
  1107. //    The third parameter on input is the requested number of tic marks.  This function will
  1108. //    set the output third parameter to the number of tic marks that together with the specified
  1109. //    min and max values provide "nice" intervals and labels.
  1110. //
  1111. //    The forth parameter is set upon return to a good value for the number of minor tic marks
  1112. //    inside each major tic-mark interval.
  1113. //
  1114. //    The fifth parameter is the number of significat figures required to represent the "nice"
  1115. //    labels.
  1116. //
  1117. //    Original algorithm by R. M. Emmons (c. 1987).
  1118.  
  1119.  
  1120. function makeSmartLabels(w)
  1121.     Wave w
  1122.     
  1123.     Variable xmin=w[0],xmax=w[1],numTics=w[2],numMinorTics=w[3],numDigits=w[4]
  1124.     
  1125.     if(numTics<=0)
  1126.         Abort "The number of tic marks must be positive"
  1127.     endif
  1128.     
  1129.     Make /o/n=4     tmpGood={10,2,3,5}
  1130.     
  1131.     variable LDX=(xmax-xmin)/numTics
  1132.     numTics+=1
  1133.     
  1134.     variable     tmp,ord,order
  1135.     variable     i=0,j;
  1136.     variable    outXmax,outXmin,imin,imax,basis,tntics,varOrder,ntic,minor
  1137.     
  1138.     do
  1139.     
  1140.         tmp=LDX/10
  1141.         tmp=log(tmp)
  1142.         ord=trunc(tmp)
  1143.         j=0
  1144.         
  1145.         do
  1146.             varOrder=ord+j
  1147.             basis=tmpGood[i]*10^varOrder
  1148.             imin=trunc(floor(xmin/basis))
  1149.             imax=ceil(xmax/basis)
  1150.             tntics=imax-imin+1
  1151.             
  1152.             if(abs(tntics-numTics) < abs(ntic-numTics))
  1153.                 outXmax=imax*basis
  1154.                 outXmin=imin*basis
  1155.                 ntic=tntics
  1156.                 numDigits=abs(varOrder)
  1157.                 minor=i
  1158.             endif
  1159.             j +=1
  1160.         while(j<=1)
  1161.         
  1162.         i +=1
  1163.     while(i<4)
  1164.     
  1165.     //     load for return
  1166.     w[0]=outXmin
  1167.     w[1]=outXmax
  1168.     w[2]=ntic-1
  1169.     w[3]=minor
  1170.     w[4]=numDigits
  1171.  
  1172.     // cleanup
  1173.     KillWaves tmpGood
  1174. end
  1175.  
  1176. ////////////////////////////////////////////////////////////////////
  1177.  
  1178. ////////////////////////////////////////////////////////////////////
  1179.  
  1180. Function/S AxisListForMenu(graphName)
  1181.     String graphName
  1182.     
  1183.     String s = "(None"
  1184.     
  1185.     if (strlen(graphName) == 0)        // convert "" into active graph
  1186.         graphName = WinName(0,1)
  1187.     endif
  1188.     if (wintype(graphName) == 1)
  1189.         s = AxisList(graphName)
  1190.         if (strlen(s) == 0)
  1191.             s = "(No Axes in Graph"
  1192.         endif
  1193.     endif
  1194.     return s
  1195. End
  1196.  
  1197. ////////////////////////////////////////////////////////////////////
  1198.  
  1199. ////////////////////////////////////////////////////////////////////
  1200.  
  1201.  
  1202. Function DAButtonProc(ctrlName) : ButtonControl
  1203.     String ctrlName
  1204.         
  1205.     GetWindow DerivedAxisControl wsize
  1206.     
  1207.     if(cmpstr(ctrlName,"bFew")==0)
  1208.         Button $ctrlName, title="More Choices",rename=bMore
  1209.         MoveWindow  V_left,V_top,V_right,V_bottom-105
  1210.         Button bMore_2 pos={1000,1000}
  1211.     else
  1212.         Button $ctrlName, title="Fewer Choices",rename=bFew
  1213.         MoveWindow  V_left,V_top,V_right,V_bottom+105
  1214.         Button bMore_2 pos={316,170}
  1215.     endif
  1216. End
  1217.  
  1218. ////////////////////////////////////////////////////////////////////
  1219.  
  1220. ////////////////////////////////////////////////////////////////////
  1221.  
  1222.  
  1223. Function popupFontSizeProc(ctrlName,popNum,popStr) : PopupMenuControl
  1224.     String ctrlName
  1225.     Variable popNum
  1226.     String popStr
  1227.  
  1228.     NVAR    gDA_FontSize=root:Packages:WM_DrawingAxis:gDA_FontSize
  1229.  
  1230.     if(strlen(popStr)>0)
  1231.         gDA_FontSize=str2num(popStr)
  1232.     endif
  1233.     
  1234. End
  1235.  
  1236. ////////////////////////////////////////////////////////////////////
  1237.  
  1238. ////////////////////////////////////////////////////////////////////
  1239.  
  1240.  
  1241. Function setvarFontSizeProc(ctrlName,varNum,varStr,varName) : SetVariableControl
  1242.     String ctrlName
  1243.     Variable varNum
  1244.     String varStr
  1245.     String varName
  1246.  
  1247.     NVAR    gDA_FontSize=root:Packages:WM_DrawingAxis:gDA_FontSize
  1248.     
  1249.     gDA_FontSize=varNum
  1250. End
  1251.  
  1252. ////////////////////////////////////////////////////////////////////
  1253.  
  1254. ////////////////////////////////////////////////////////////////////
  1255.  
  1256.  
  1257. Function popupDerivedScalingProc(ctrlName,popNum,popStr) : PopupMenuControl
  1258.     String ctrlName
  1259.     Variable popNum
  1260.     String popStr
  1261.  
  1262.     if(popNum==1)
  1263.         popupmenu popupRefAxis         pos={1000,1000}
  1264.         popupmenu popupScalingFunc     pos={1000,1000}
  1265.         SetVariable funcString             pos={1000,1000}
  1266.         popupmenu popupLabelingType     pos={1000,1000}
  1267.         popupmenu popupTicWave         pos={1000,1000}
  1268.         SetVariable setvarLowerLimit    pos={14,71}
  1269.         SetVariable setvarUpperLimit    pos={215,71}
  1270.         SetVariable setvarInterval        pos={14,94}
  1271.         SetVariable setvarSigDigits        pos={279,139}
  1272.         SetVariable setvarNumTics        pos={1000,1000}    
  1273.     else
  1274.         popupmenu popupRefAxis         pos={11,65}
  1275.         popupmenu popupScalingFunc     pos={207,65}
  1276.         popupmenu popupLabelingType     pos={11,115}
  1277.         SetVariable funcString             pos={14,90}
  1278.         SetVariable setvarLowerLimit    pos={1000,1000}
  1279.         SetVariable setvarUpperLimit    pos={1000,1000}
  1280.         SetVariable setvarInterval        pos={1000,1000}
  1281.         // checkbox    checkNiceLabels        pos={1000,1000}
  1282.  
  1283.         ControlInfo popupLabelingType
  1284.         variable externalSelection=V_value
  1285.         do
  1286.             if(externalSelection==3)
  1287.                 PopupMenu popupTicWave        pos={11,139}
  1288.                 SetVariable setvarNumTics        pos={1000,1000}    
  1289.                 SetVariable setvarSigDigits        pos={279,139}    
  1290.                 break
  1291.             endif
  1292.             
  1293.             if(externalSelection==2)
  1294.                 SetVariable setvarSigDigits        pos={1000,1000}    
  1295.                 SetVariable setvarNumTics        pos={1000,1000}    
  1296.                 break
  1297.             endif
  1298.             
  1299.             if(externalSelection==1)
  1300.                 SetVariable setvarNumTics        pos={11,139}
  1301.                 SetVariable setvarSigDigits        pos={279,139}    
  1302.                 break
  1303.             endif
  1304.         while(0)
  1305.         
  1306.     endif    
  1307. End
  1308.  
  1309. ////////////////////////////////////////////////////////////////////
  1310.  
  1311.  
  1312. ////////////////////////////////////////////////////////////////////
  1313.  
  1314. Function popupLabelingTypeProc(ctrlName,popNum,popStr) : PopupMenuControl
  1315.     String ctrlName
  1316.     Variable popNum
  1317.     String popStr
  1318.  
  1319.     
  1320.     SetVariable setvarNumTics        pos={1000,1000}    
  1321.     SetVariable setvarSigDigits        pos={1000,1000}    
  1322.     PopupMenu popupTicWave        pos={1000,1000}
  1323.     
  1324.     do
  1325.         if(popNum==3)
  1326.             PopupMenu popupTicWave        pos={11,139}
  1327.             SetVariable setvarNumTics        pos={1000,1000}    
  1328.             SetVariable setvarSigDigits        pos={279,139}    
  1329.             break
  1330.         endif
  1331.         
  1332.         if(popNum==2)
  1333.             SetVariable setvarSigDigits        pos={1000,1000}    
  1334.             SetVariable setvarNumTics        pos={1000,1000}    
  1335.             break
  1336.         endif
  1337.         
  1338.         if(popNum==1)
  1339.             SetVariable setvarNumTics        pos={11,139}
  1340.             SetVariable setvarSigDigits        pos={279,139}    
  1341.             break
  1342.         endif
  1343.     while(0)
  1344. End
  1345.  
  1346. ////////////////////////////////////////////////////////////////////
  1347.  
  1348. ////////////////////////////////////////////////////////////////////
  1349.  
  1350. Function bMore_2Proc(ctrlName) : ButtonControl
  1351.     String ctrlName
  1352.  
  1353.     GetWindow DerivedAxisControl wsize
  1354.     
  1355.     if(cmpstr(ctrlName,"bFew_2")==0)
  1356.         Button $ctrlName, title="Even More",rename=bMore_2
  1357.         MoveWindow  V_left,V_top,V_right,V_bottom-80
  1358.         Button bFew  pos={225,169}
  1359.     else
  1360.         Button $ctrlName, title="Fewer Choices",rename=bFew_2
  1361.         MoveWindow  V_left,V_top,V_right,V_bottom+80
  1362.         Button bFew  pos={1000,1000}
  1363.     endif
  1364. End
  1365.  
  1366. ////////////////////////////////////////////////////////////////////
  1367.  
  1368. ////////////////////////////////////////////////////////////////////
  1369.  
  1370. Function popupScalingFuncProc(ctrlName,popNum,popStr) : PopupMenuControl
  1371.     String ctrlName
  1372.     Variable popNum
  1373.     String popStr
  1374.  
  1375.     SVAR    gDA_ScalingFunc=root:Packages:WM_DrawingAxis:gDA_ScalingFunc
  1376.  
  1377.     do
  1378.         if(popNum==2)
  1379.             gDA_ScalingFunc="32+9*x/5"
  1380.             break;
  1381.         endif
  1382.         if(popNum==3)
  1383.             gDA_ScalingFunc="(x-32)*5/9"
  1384.             break;
  1385.         endif
  1386.         if(popNum==1)
  1387.             gDA_ScalingFunc=""
  1388.             break;
  1389.         endif
  1390.     while(0)
  1391. End
  1392.  
  1393. ////////////////////////////////////////////////////////////////////
  1394.  
  1395. ////////////////////////////////////////////////////////////////////
  1396.  
  1397. Function CheckProc(ctrlName,checked) : CheckBoxControl
  1398.     String ctrlName
  1399.     Variable checked
  1400.  
  1401.     if(checked)
  1402.         SetVariable setvarSigDigits        pos={1000,1000}
  1403.     else
  1404.         SetVariable setvarSigDigits        pos={279,139}
  1405.     endif
  1406. End
  1407.  
  1408. ////////////////////////////////////////////////////////////////////
  1409.  
  1410. ////////////////////////////////////////////////////////////////////
  1411.  
  1412. Function bMoreProc(ctrlName) : ButtonControl
  1413.     String ctrlName
  1414.         
  1415.     GetWindow DerivedAxisControl wsize
  1416.     
  1417.     if(cmpstr(ctrlName,"bFew")==0)
  1418.         Button $ctrlName, title="More Choices",rename=bMore
  1419.         MoveWindow  V_left,V_top,V_right,V_bottom-105
  1420.         Button bMore_2 pos={1000,1000}
  1421.     else
  1422.         Button $ctrlName, title="Fewer Choices",rename=bFew
  1423.         MoveWindow  V_left,V_top,V_right,V_bottom+105
  1424.         Button bMore_2 pos={342,169}
  1425.     endif
  1426. End
  1427. ////////////////////////////////////////////////////////////////////
  1428.  
  1429. ////////////////////////////////////////////////////////////////////
  1430.  
  1431. Function ApplyButtonProc(ctrlName) : ButtonControl
  1432.     String ctrlName
  1433.     myDrawDerivedAxis()
  1434. End
  1435.  
  1436. ////////////////////////////////////////////////////////////////////
  1437.  
  1438. ////////////////////////////////////////////////////////////////////
  1439.  
  1440. Function SetVarLineColor(ctrlName,varNum,varStr,varName) : SetVariableControl
  1441.     String ctrlName
  1442.     Variable varNum
  1443.     String varStr
  1444.     String varName
  1445.     
  1446.     drawLineColor()
  1447. End
  1448.  
  1449. ////////////////////////////////////////////////////////////////////
  1450.  
  1451. ////////////////////////////////////////////////////////////////////
  1452.  
  1453. Function SetVarTextColor(ctrlName,varNum,varStr,varName) : SetVariableControl
  1454.     String ctrlName
  1455.     Variable varNum
  1456.     String varStr
  1457.     String varName
  1458.  
  1459.     drawLineColor()
  1460. End
  1461.  
  1462. ////////////////////////////////////////////////////////////////////
  1463.  
  1464. ////////////////////////////////////////////////////////////////////
  1465.  
  1466. Function CheckFontFace(ctrlName,checked) : CheckBoxControl
  1467.     String ctrlName
  1468.     Variable checked
  1469.     
  1470.     if(cmpstr(ctrlName,"checkFontPlain")!=0)
  1471.         CheckBox checkFontPlain value=0
  1472.     endif
  1473.  
  1474.     NVAR    gDA_FontFace=root:Packages:WM_DrawingAxis:gDA_FontFace
  1475.  
  1476.     ControlInfo checkFontPlain
  1477.     gDA_FontFace=0
  1478.     if(V_value==1)    
  1479.         CheckBox checkFontPlain value=1
  1480.         CheckBox checkFontBold value=0
  1481.         CheckBox checkFontItalic value=0
  1482.         CheckBox checkFontUnderline value=0
  1483.         CheckBox checkFontOutline value=0
  1484.         CheckBox checkFontShadow value=0
  1485.     else
  1486.         ControlInfo checkFontBold
  1487.         if(V_value)
  1488.             gDA_FontFace+=1
  1489.         endif
  1490.         ControlInfo checkFontItalic
  1491.         if(V_value)
  1492.             gDA_FontFace+=2
  1493.         endif
  1494.         ControlInfo checkFontUnderline
  1495.         if(V_value)
  1496.             gDA_FontFace+=4
  1497.         endif
  1498.         ControlInfo checkFontOutline
  1499.         if(V_value)
  1500.             gDA_FontFace+=8
  1501.         endif
  1502.         ControlInfo checkFontShadow
  1503.         if(V_value)
  1504.             gDA_FontFace+=16
  1505.         endif
  1506.     endif
  1507. End
  1508.  
  1509. ////////////////////////////////////////////////////////////////////
  1510.  
  1511. ////////////////////////////////////////////////////////////////////
  1512.  
  1513. Function SetVarScaleFunc1(ctrlName,varNum,varStr,varName) : SetVariableControl
  1514.     String ctrlName
  1515.     Variable varNum
  1516.     String varStr
  1517.     String varName
  1518.  
  1519.     SVAR    gDA_ScalingFunc=root:Packages:WM_DrawingAxis:gDA_ScalingFunc
  1520.  
  1521.     gDA_ScalingFunc=varStr
  1522.  
  1523. End
  1524.  
  1525. ////////////////////////////////////////////////////////////////////
  1526.  
  1527. ////////////////////////////////////////////////////////////////////
  1528.  
  1529.  
  1530. Window Table0() : Table
  1531.     PauseUpdate; Silent 1        // building window...
  1532.     Edit/W=(5,42,510,249) tick
  1533. EndMacro
  1534.  
  1535. ////////////////////////////////////////////////////////////////////
  1536.  
  1537. ////////////////////////////////////////////////////////////////////
  1538.  
  1539. Proc DerivedAxisControl()
  1540.     PauseUpdate; Silent 1        // building window...
  1541.     NewPanel /W=(182,128,643,325)
  1542.     SetDrawLayer ProgBack
  1543.     DrawLine -13,196,460,196
  1544.     DrawLine -15,301,458,301
  1545.     SetDrawEnv fname= "Chicago"
  1546.     DrawText 11,320,"Line Color:"
  1547.     SetDrawEnv fname= "Chicago"
  1548.     DrawText 235,320,"Text Color:"
  1549.     SetDrawEnv fname= "Chicago"
  1550.     DrawText 19,218,"Draw axis between"
  1551.     SetDrawEnv fname= "Chicago"
  1552.     DrawText 77,241,"and"
  1553.     SetDrawEnv fname= "Chicago"
  1554.     DrawText 171,242,"%"
  1555.     DrawLine -14,161,459,161
  1556.     SetDrawLayer UserBack
  1557.     SetDrawEnv fillfgc= (0,0,0)
  1558.     DrawRect 10,321,60,371
  1559.     SetDrawEnv fillfgc= (0,0,0)
  1560.     DrawRect 240,321,290,371
  1561.     Button bApply,pos={10,169},size={50,20},proc=ApplyButtonProc,title="Apply"
  1562.     PopupMenu popupNewPosition,pos={11,8},size={174,19},title="Position New Axis:"
  1563.     PopupMenu popupNewPosition,mode=4,value= #"\"Bottom;Left;Right;Top\""
  1564.     PopupMenu popupDerivedScaling,pos={10,38},size={362,19},proc=popupDerivedScalingProc,title="Label New Axis With:"
  1565.     PopupMenu popupDerivedScaling,mode=2,value= #"\"User defined range;Direct scaling of another axis\""
  1566.     PopupMenu popupScalingFunc,pos={207,65},size={234,19},proc=popupScalingFuncProc,title="Scaling Function:"
  1567.     PopupMenu popupScalingFunc,mode=1,value= #"\"User Specified;C to F;F to C\""
  1568.     Button bMore,pos={225,169},size={110,20},proc=bMoreProc,title="More Choices"
  1569.     PopupMenu popupFontSize,pos={421,226},size={19,19},proc=popupFontSizeProc
  1570.     PopupMenu popupFontSize,mode=0,value= #"\"5;7;9;10;12;14;18;24;36;48;72\""
  1571.     PopupMenu popupRefAxis,pos={11,65},size={166,19},title="Reference Axis:"
  1572.     PopupMenu popupRefAxis,mode=1,value= #"AxisListForMenu(\"\")"
  1573.     SetVariable setvarLowerLimit,pos={1000,1000},size={175,17},title="Lower Limit:"
  1574.     SetVariable setvarLowerLimit,font="Chicago"
  1575.     SetVariable setvarLowerLimit,limits={-INF,INF,0.005},value=gDA_LowerLimit
  1576.     SetVariable setvarInterval,pos={1000,1000},size={230,17},title="Interval between Ticks:"
  1577.     SetVariable setvarInterval,font="Chicago"
  1578.     SetVariable setvarInterval,limits={-INF,INF,0.005},value=gDA_Interval
  1579.     SetVariable setvarUpperLimit,pos={1000,1000},size={175,17},title="Upper Limit:"
  1580.     SetVariable setvarUpperLimit,font="Chicago",format="%g"
  1581.     SetVariable setvarUpperLimit,limits={-INF,INF,0.005},value=gDA_UpperLimit
  1582.     SetVariable setvarSigDigits,pos={1000,1000},size={160,17},title="Significant Digits"
  1583.     SetVariable setvarSigDigits,font="Chicago"
  1584.     SetVariable setvarSigDigits,limits={0,INF,1},value=gDA_SignificantDigits
  1585.     SetVariable funcString,pos={14,90},size={425,17},title="Function:"
  1586.     SetVariable funcString,font="Chicago",limits={-INF,INF,1},value=gDA_ScalingFunc
  1587.     PopupMenu popupLabelingType,pos={11,115},size={319,19},proc=popupLabelingTypeProc,title="Labeling Type:"
  1588.     PopupMenu popupLabelingType,mode=1,value= #"\"Hard-Wired to Reference Axis;Rounded Labels;User Specified Tick-Mark Position Wave\""
  1589.     PopupMenu popupTicWave,pos={1000,1000},size={135,19},title="Tick-Mark Wave:"
  1590.     PopupMenu popupTicWave,mode=11,value= #"WaveList(\"!tmp_qq*\",\";\",\"\")"
  1591.     PopupMenu popupFont,pos={299,201},size={112,19},title="Font:"
  1592.     PopupMenu popupFont,mode=4,popvalue=GetDefaultFont(WinName(0, 1)),value= #"FontList(\";\")"
  1593.     Button bMore_2,pos={1000,1000},size={110,20},proc=bMore_2Proc,title="Even More"
  1594.     SetVariable setvar2,pos={18,225},size={50,17},title=" ",font="Chicago"
  1595.     SetVariable setvar2,format="%g",limits={0,100,5},value=gDA_StartDerivedAxis
  1596.     SetVariable setvar2_1,pos={115,225},size={50,17},title=" ",font="Chicago"
  1597.     SetVariable setvar2_1,format="%d",limits={0,100,5},value=gDA_EndDerivedAxis
  1598.     SetVariable setvarAxisWidth,pos={7,253},size={165,17},title="Axis Line Width:"
  1599.     SetVariable setvarAxisWidth,font="Chicago",format="%2.2f"
  1600.     SetVariable setvarAxisWidth,limits={0,INF,0.25},value=gDA_AxisLineWidth
  1601.     SetVariable setvarTickLength,pos={13,278},size={165,17},title="Tick Mark Size:"
  1602.     SetVariable setvarTickLength,font="Chicago",format="%1.2f"
  1603.     SetVariable setvarTickLength,limits={0,1,0.01},value=gDA_TicLength
  1604.     SetVariable setvarFontSize,pos={302,226},size={115,17},proc=setvarFontSizeProc,title="Font Size:"
  1605.     SetVariable setvarFontSize,font="Chicago",format="%d"
  1606.     SetVariable setvarFontSize,limits={0,72,2},value=gDA_FontSize
  1607.     SetVariable setvarLabelGrout,pos={303,249},size={135,17},title="Label Grout:"
  1608.     SetVariable setvarLabelGrout,font="Chicago",format="%1.2f"
  1609.     SetVariable setvarLabelGrout,limits={0,0.5,0.01},value=gDA_LabelGrout
  1610.     SetVariable setvarLineRed,pos={82,318},size={120,17},proc=SetVarLineColor,title="Red:"
  1611.     SetVariable setvarLineRed,font="Chicago",limits={0,65535,256},value=gDA_LineRed
  1612.     SetVariable setvarLineGreen,pos={67,338},size={135,17},proc=SetVarLineColor,title="Green:"
  1613.     SetVariable setvarLineGreen,font="Chicago"
  1614.     SetVariable setvarLineGreen,limits={0,65535,256},value=gDA_LineGreen
  1615.     SetVariable setvarLineBlue,pos={77,359},size={125,17},proc=SetVarLineColor,title="Blue:"
  1616.     SetVariable setvarLineBlue,font="Chicago"
  1617.     SetVariable setvarLineBlue,limits={0,65535,256},value=gDA_LineBlue
  1618.     SetVariable setvarTextRed,pos={313,318},size={120,17},proc=SetVarTextColor,title="Red:"
  1619.     SetVariable setvarTextRed,font="Chicago",limits={0,65535,256},value=gDA_TextRed
  1620.     SetVariable setvarTextGreen,pos={299,338},size={135,17},proc=SetVarTextColor,title="Green:"
  1621.     SetVariable setvarTextGreen,font="Chicago"
  1622.     SetVariable setvarTextGreen,limits={0,65535,256},value=gDA_TextGreen
  1623.     SetVariable setvarTextBlue,pos={309,358},size={125,17},proc=SetVarTextColor,title="Blue:"
  1624.     SetVariable setvarTextBlue,font="Chicago"
  1625.     SetVariable setvarTextBlue,limits={0,65535,256},value=gDA_TextBlue
  1626.     CheckBox checkFontPlain,pos={206,197},size={75,20},proc=CheckFontFace,title="Plain",value=1
  1627.     CheckBox checkFontBold,pos={206,213},size={75,20},proc=CheckFontFace,title="Bold",value=0
  1628.     CheckBox checkFontItalic,pos={206,229},size={75,20},proc=CheckFontFace,title="Italic",value=0
  1629.     CheckBox checkFontUnderline,pos={206,245},size={90,20},proc=CheckFontFace,title="Underline",value=0
  1630.     CheckBox checkFontOutline,pos={206,261},size={85,20},proc=CheckFontFace,title="Outline",value=0
  1631.     CheckBox checkFontShadow,pos={206,277},size={85,20},proc=CheckFontFace,title="Shadow",value=0
  1632.     SetVariable setvarNumTics,pos={11,139},size={185,17},title="Number of Intervals:"
  1633.     SetVariable setvarNumTics,font="Chicago",format="%d"
  1634.     SetVariable setvarNumTics,limits={0,50,1},value=gDA_requestedTicMarks
  1635.     Button bErase,pos={100,169},size={90,20},proc=ButtonProcEraseLayer,title="Erase Layer"
  1636. EndMacro
  1637.  
  1638.